<template>
  <!-- 关锁信息 -->
  <el-dialog :title="dialogType + '集装箱(器)封志信息'" :visible.sync="dialogVisible" :before-close="closedialog" width="800"
    append-to-body :close-on-click-modal="false">
    <div>
      <el-form ref="formData" :model="form" :rules="rules" label-width="168px" label-suffix=":" size="mini"
        class="bill-form" width="600">
        <el-row>
          <el-col :span="8">
            <el-form-item label="封志类型" prop="sealType">
              <el-select  v-model.trim="form.sealType" placeholder="请输入封志类型">
                <el-option v-for="(item, index) in dict.type.mft_conta_seal_type" :key="index"
                  :label="item.value+'-'+item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="封志号码" prop="sealNo">
              <el-input  v-model="form.sealNo" placeholder="封志号码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="施加封志人" prop="sealPerson">
              <el-select  v-model.trim="form.sealPerson" placeholder="请输入施加封志人">
                <el-option v-for="(item, index) in dict.type.mft_conta_seal_person" :key="index"
                  :label="item.value+'-'+item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <span style="color: red;font-size: 12px;">注意事项：以上字段跨境快速通关时必填,格式为M（机械封志）或E（电子封志）+"/" +封志号码，特种重箱填写“0000”</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label-width="20px">
              <el-button type="primary" plain @click="addForm" size="mini">添加</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <basic-table ref="tableList" :columns="columns" :tableData="tableData" :needPagination="false">
        <template #operate="scope">
          <div class="option-menu">
            <el-button type="text" size="mini" class="table-edit" @click="handleDelete(scope.index, tableData)"
              v-hasPermi="['system:costStopConfig:delete']">
              移除
            </el-button>
          </div>
        </template>
        <template #sealType="scope">
          <dict-tag :options="dict.type.mft_conta_seal_type" :value="scope.row.sealType" />
        </template>
        <template #sealPerson="scope">
          <dict-tag :options="dict.type.mft_conta_seal_person" :value="scope.row.sealPerson" />
        </template>

      </basic-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm('formData')" size="small" v-if="dialogType != 'detail'">确定
      </el-button>
      <el-button @click="closedialog('formData')" size="small">取消</el-button>
    </span>
  </el-dialog>


</template>



<script>
  export default {
    name: "contasealInfo",
    dicts: ["mft_conta_seal_type","mft_conta_seal_person"],
    props: {
      sealList: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        tableData: [],
        columns: [{
            prop: "sealType",
            label: "封志类型",
            align: "center",
            slot: true
          },
          {
            prop: "sealNo",
            label: "封志号码",
            align: "center",
          },
          {
            prop: "sealPerson",
            label: "施加封志人",
            align: "center",
             slot: true
          },
          {
            prop: "operate",
            label: "操作",
            slot: true,
            width: 150,
            fixed: "right",
          },
        ],
        dialogVisible: false,
        dialogType: "新增",
        editIndex: null,
        form: {},
        rules: {
          sealType: [{
            required: true,
            message: "封志类型不能为空",
            trigger: "blur",
          }, ],
          sealNo: [{
            required: true,
            message: "封志号码不能为空",
            trigger: "blur",
          }, ],
          sealPerson: [{
            required: true,
            message: "施加封志人不能为空",
            trigger: "blur",
          }, ],
        },
      };
    },
    methods: {
      initForm() {
        this.form = {
          sealType: null,
          sealNo: null,
          sealPerson:null
        };
      },
      handleAdd() {
        this.initForm();
        this.dialogType = "新增";
        this.tableData.push(this.form);
      },
      open() {
        this.dialogVisible = true;
        this.initForm();
        if (this.sealList.length > 0) {
          this.tableData = this.sealList;
        }
      },
      closedialog() {
        this.$refs["formData"].resetFields();
        this.tableData = [];
        this.dialogVisible = false;
      },
      handleDelete(index, rows) {
        rows.splice(index, 1);
      },
      addForm() {
        this.$refs["formData"].validate((valid) => {
          if (valid) {
            let list = this.tableData.map(item => item.sealNo);
            if (list.indexOf(this.form.sealNo) != -1) {
              this.$message.warning("海关关锁号编号已存在!")
              return;
            }
            this.tableData.push(this.form);
            this.dialogType == "新增";
            this.initForm();
          }
        });
      },
      submitForm() {
        if(this.tableData.length==0){
          this.$message.warning("集装箱封志信息为空!")
          return;
        }
        this.$emit("submitSealInfo", this.tableData);
        this.closedialog();
      }
    },
  };
</script>

<style lang="scss" scoped>
  ::v-deep .el-empty {
    padding: 0;
  }

  ::v-deep .el-empty__image {
    width: 80px !important;
  }

  ::v-deep .el-empty__description {
    margin-top: 0;

    p {
      font-size: 12px;
    }
  }

  ::v-deep .el-table {
    th {
      background-color: #ECF5FF;
      color: #333;
    }
  }
</style>
